<%@ page import="com.xunfang.bean.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: 李赏赏
  Date: 2024/6/11
  Time: 14:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--
1、el表达式
    作用:让jsp页面书写更加简洁，用来替代java表达式。只能获取值，不能设置值
2、接收作用域的值
--%>
<%

    session.setAttribute("name","王五");
    application.setAttribute("name","赵六");
    pageContext.setAttribute("name","张三");
    request.setAttribute("name","李四");

%>
<%--
    1、从作用域中开始检索name的值，从小到大依次检索，从pageContext-request-session-application
    依次检索，找到了不会继续去检索，如果检索完毕还没有找到，返回一个空

    2、从指定的作用域进行检索
        ${pageScope.name}           从pageContext中检索
        ${requestScope.name}        从request中检索
        ${sessionScope.name}        从session中检索
        ${applicationScope.name}    从application中检索

--%>
${name}
${pageScope.name}
${requestScope.name}
${sessionScope.name}
${applicationScope.name} <br>


<%
    User user = new User(1,"张三");
    request.setAttribute("user",user);

    User[] arr = {new User(2,"李四"),new User(3,"王五")};
    request.setAttribute("arr",arr);

    List<User> list = new ArrayList<>();
    list.add(new User(1,"李四1"));
    list.add(new User(2,"李四2"));
    list.add(new User(3,"李四3"));
    list.add(new User(4,"李四4"));
    request.setAttribute("userList",list);

    Map<String,User> map = new HashMap<>();
    map.put("key1",new User(1,"王五1"));
    map.put("key2",new User(2,"王五2"));
    map.put("key3",new User(3,"王五3"));
    map.put("key4",new User(4,"王五4"));
    request.setAttribute("map",map);


%>

<%--toString方法--%>
${user } <br>
<%--获取javabean的属性值   对象.属性名   本质上是通过get方法进行获取值--%>
${user.id } <br>
${user.name } <br>
<%--获取数组中的元素  数组名[索引]  --%>
${arr[1]} <br>
${arr[0].name} <br>

<%--获取集合中的元素  单列集合名[索引] --%>
${userList[1].name} <br>
${userList[2].id} <br>

<%--获取map中的元素(通过key获取value)    map[key]  或者 map.get(key)--%>
${map["key2"].name} <br>
${map.get("key3").name} <br>



</body>
</html>
